package com.example.project.projectspringcloud.service.impl;

import com.example.project.projectspringcloud.dao.user.UserMapper;
import com.example.project.projectspringcloud.dao.video.VideoMapper;
import com.example.project.projectspringcloud.entity.user.User;
import com.example.project.projectspringcloud.entity.video.Video;
import com.example.project.projectspringcloud.service.StatisticsService;
import com.example.project.projectspringcloud.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private VideoMapper videoMapper;

    @Override
    public Map someCount() throws Exception {
        Map<String, Object> result = new HashMap<>();

        User entity = new User();
        result.put("userCount", userMapper.selectCount(entity));

        entity.setType(4);
        result.put("photographerCount", userMapper.selectCount(entity));

        entity.setType(5);
        result.put("scriptwriterCount", userMapper.selectCount(entity));

        Video videoEntity = new Video();
        result.put("videoCount", videoMapper.selectCount(videoEntity));

        videoEntity.setType(1);
        result.put("workCount", videoMapper.selectCount(videoEntity));

        videoEntity.setType(2);
        result.put("loveCount", videoMapper.selectCount(videoEntity));

        result.put("localhostIP", WebUtil.getLocalHostLANAddress().getHostAddress());
        return result;
    }
}
